const path = require('path')
const chalk = require('chalk');

// const CompressionPlugin = require('compression-webpack-plugin')
const TerserPlugin = require('terser-webpack-plugin');

// function resolve(dir) {
//   return path.join(__dirname, dir)
// }
module.exports = {
  productionSourceMap:false,
  publicPath: "./",
  lintOnSave: false,
  devServer: {
    port: 8090,
    proxy: {
      "/api": {
        target: "http://target.test.com",
      }
    },
  },
  css: {
    loaderOptions: {
      less: {
        modifyVars: {
          "primary-color": "#0085D0",
          "border-color-base": "#dddddd",
          "border-radius-base": "5px"
        },
        javascriptEnabled: true
      }
    }
  },
  configureWebpack: {
    // plugins: [new CompressionPlugin({
    //   test: /\.js$|\.html$|\.css/,
    //   threshold: 10240, //对超过10k的数据压缩
    //   deleteOriginalAssets: false //不删除源文件
    // })],
    optimization: {
      minimizer: [
        new TerserPlugin({
          terserOptions: {
            ecma: undefined,
            warnings: false,
            parse: {},
            compress: {
              drop_console: true,
              drop_debugger: false,
              pure_funcs: ['console.log'] // 移除console
            }
          },
        }),
      ]
    }
  },
  chainWebpack(config) {
    config.plugin('preload').tap(() => [
      {
        rel: 'preload',
        fileBlacklist: [/\.map$/, /hot-update\.js$/, /runtime\..*\.js$/],
        include: 'initial'
      }
    ])
    // config.plugins.delete('prefetch')
    config
      .when(process.env.NODE_ENV !== 'development',
        config => {
          config
            .optimization.splitChunks({
              chunks: 'all',
              cacheGroups: {
                libs: {
                  name: 'chunk-libs',
                  test: /[\\/]node_modules[\\/]/,
                  priority: 10,
                  chunks: 'initial'
                },
                antdUI: {
                  name: 'chunk-antdUI',
                  priority: 20,
                  test: /[\\/]node_modules[\\/]_?ant-design-vue(.*)/
                }
              }
            })
          config.optimization.runtimeChunk('single')
        }
      )
  }
};
